package d8_stream;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 2024/6/7 Stream流 Cjj 10：18
 */
public class StreamTest1 {
    public static void main(String[] args) {
        List<String> names = new ArrayList<>();
        Collections.addAll(names, "张三三", "张五五", "刘敏", "张强");
        System.out.println(names);

        System.out.println("");
        //找出姓张的 且3个字的元素放入新的集合中
        List<String> list = new ArrayList<>();
        for (String name : names) {
            if (name.startsWith("张") && name.length() == 3) {
                list.add(name);
            }
        }
        System.out.println(list);

        //使用stream流
        List<String> stringList = names.stream().filter(s -> s.startsWith("张")).filter(o -> o.length() == 3)
                .collect(Collectors.toList());
        System.out.println(stringList);
    }
}